<?php
header("Content-Type: text/html; charset=iso-8859-1");
require('include.php');
if(!isset($FichierComplementLabel)){$FichierComplementLabel = 1;
	function complement_label($val){
	        global $max_y;
	// return $val;    
	return $max_y - $val + 1;
	}
	function arrondi_label($val){
	    $set0 = 0;
	    if($val>0){ $set_l = 3; $set_v = 3-$val;}
	    elseif($val == 0){$set0 = 1;}
	    else{$set_l = $val+3; $set_v = 3;}
	    if($set0) return '';
	    else   return $set_l.'-'.$set_v;
	}
}
$x = (!empty($_REQUEST['x'])) ? $_REQUEST['x'] : "labelx";
$y = (!empty($_REQUEST['y'])) ? $_REQUEST['y'] : "datay";
$type = (!empty($_REQUEST['type'])) ? $_REQUEST['type'] : "";
$datay = (!empty($_SESSION[$y])) ? $_SESSION[$y] : "";
$labelx = (!empty($_SESSION[$x])) ? $_SESSION[$x] : "";
$max_y = (!empty($_SESSION['max_y'])) ? $_SESSION['max_y'] : "";
global $max_y;
if(!$max_y) $max_y = max($datay);
$min_y = min($datay);
if($type == 'equipe'){ $max_y = '3'; $min_y = '-3';}
if($type != 'equipe') $min_y = '1';
$home = "jpgraph/";
require($home."jpgraph.php");
require($home."jpgraph_line.php");
// Creation du graphique
if($type == 'equipe') $graph = new Graph(600,300); 
else $graph = new Graph(600,200);
$graph->SetScale("textlin");

$top = 10;
if($type == 'equipe') $bottom = 160;
else $bottom = 50;
$left = 80;
$right = 20;
$graph->SetMargin($left,$right,$top,$bottom);
$graph->SetMarginColor('#FDE38B');
#$graph->SetFrame(false);
$graph->SetScale('textlin',$min_y,$max_y);
$graph->SetColor("#FFFACD");
if($type != 'classement')$graph->yaxis->title->Set("Scores");
else $graph->yaxis->title->Set("Rang");
$graph->yaxis->SetLabelMargin(12);
$graph->xaxis->SetLabelMargin(6);
$graph->yaxis->SetTickSide(SIDE_LEFT);
$graph->xaxis->SetTickSide(SIDE_DOWN);
$graph->yaxis->SetTitleMargin(60);
if($type != 'classement')$graph->yaxis->SetLabelFormatCallback("arrondi_label");
else $graph->yaxis->SetLabelFormatCallback("complement_label");
$graph->xgrid->Show(true,true);
$graph->ygrid->Show(true,true);
$graph->xgrid->SetColor('gray@0.5');
$graph->ygrid->SetColor('gray@0.5');
$graph->yscale-> ticks->Set(1 ,1); 
#$graph->SetGridColor('#FAEAB6');
if($type == 'classement'){
	for($i = 0; $i < count($datay); $i++){
		$datay[$i] = $max_y - $datay[$i] + 1;
	}
}
// Creation du systeme de points
$lineplot=new LinePlot($datay);
#$lineplot->SetStepStyle();
$lineplot->SetColor('#723B09');
$lineplot->SetWeight(2);
// On rajoute les points au graphique
$graph->Add($lineplot);

// Ajout des label X
$graph->xaxis->SetTickLabels($labelx);
#$graph->xaxis->SetFont(FF_ARIAL,FS_NORMAL,8);
$graph->xaxis->SetLabelAngle(90);
$graph->xaxis->SetPos('min');
//Ajout ligne a 0
if($type != 'classement') {
	$line = new PlotLine(HORIZONTAL,0,"red",2);
	$graph->AddLine($line);
}

// Affichage
$graph->img->SetAntiAliasing();
$graph->Stroke();
if(isset($_SESSION[$x])) unset($_SESSION[$x]);
if(isset($_SESSION[$y])) unset($_SESSION[$y]);
// if(isset($_SESSION["max_y"])) unset($_SESSION["max_y"]);


?>
